home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 April / EnigmA AMIGA RUN 17 (1997)(G.R. Edizioni)(IT)[!][issue 1997-04][EAR-CD].iso / EARCD / comm / bbs / Hydra11s.lha / HBBS / Source / Doors_System / CmdPrompt / CmdPrompt.C < prev    next >
C/C++ Source or Header  |  1996-10-31  |  4KB  |  192 lines

  1. /*
  2.  
  3.   function of cmdprompt door
  4.  
  5.   - run user doors.
  6.  
  7. */
  8. #include <exec/types.h>
  9. #include <exec/memory.h>
  10. #include <dos/dos.h>
  11. #include <clib/exec_protos.h>
  12. #include <clib/alib_protos.h>
  13. #include <clib/dos_protos.h>
  14.  
  15. #include <stdlib.h>
  16. #include <string.h>
  17. #include <stdio.h>
  18. #include <ctype.h>
  19. #include <time.h>
  20.  
  21.  
  22. #ifdef __SASC
  23. int CXBRK(void) { return(0); }
  24. int _CXBRK(void) { return(0); }
  25. void chkabort(void) {}
  26. #endif
  27.  
  28. #include <HBBS/ANSI_Codes.h>
  29. #include <HBBS/Defines.h>
  30. #include <HBBS/types.h>
  31. #include <HBBS/structures.h>
  32. #include <HBBS/Access.h>
  33. #include <HBBS/hbbscommon_protos.h>
  34. #include <HBBS/hbbscommon_pragmas.h>
  35. #include <HBBS/Hbbsnode_protos.h>
  36. #include <HBBS/Hbbsnode_pragmas.h>
  37. #include <HBBS/release.h>
  38. char *versionstr="$VER: CmdPrompt "RELEASE_STR;
  39.  
  40. struct Library *HBBSCommonBase=NULL;
  41. struct Library *HBBSNodeBase=NULL;
  42.  
  43. struct BBSGlobalData *BBSGlobal=NULL;
  44. struct NodeData *N_ND=NULL;
  45. int N_NodeNum=-1;
  46. char outstr[1024];
  47.  
  48. static VOID cleanup(ULONG num)
  49. {
  50.   if (HBBSNodeBase)
  51.   {
  52.     HBBS_CleanUpDoor();
  53.     CloseLibrary (HBBSNodeBase);
  54.   }
  55.  
  56.   if (HBBSCommonBase)
  57.   {
  58.     HBBS_CleanUpCommon();
  59.     CloseLibrary (HBBSCommonBase);
  60.   }
  61.  
  62.   if (num) printf("Door Error = %d\n",num);
  63.  
  64.   exit(0);
  65. }
  66.  
  67. static VOID init(char *name)
  68. {
  69.   if(!(HBBSCommonBase = OpenLibrary("HBBSCommon.library",0)))
  70.   {
  71.     cleanup(1);
  72.   }
  73.  
  74.   if (!(HBBS_InitCommon()))
  75.   {
  76.     cleanup(2);
  77.   }
  78.  
  79.   if(!(HBBSNodeBase = OpenLibrary("HBBSNode.library",0)))
  80.   {
  81.     cleanup(3);
  82.   }
  83.  
  84.   if (!(HBBS_InitDoor(N_NodeNum,name)))
  85.   {
  86.     cleanup(4);
  87.   }
  88.   SetProgramName(name);
  89. }
  90.  
  91. void DoorMain( void )
  92. {
  93.   char command[80],doorname[80],options[80],prompt[80];
  94.   short tmpval;
  95.   BOOL skipmenu=FALSE;
  96.   do
  97.   {
  98.     doorname[0]=0;
  99.  
  100.  
  101.     if ((N_ND->User.CallData.UserType==USERTYPE_NORMAL) && (skipmenu==FALSE))
  102.     {
  103.       DOOR_PausePrompt(NULL);
  104.       DOOR_DisplaySpecialScreen("MENU");
  105.     }
  106.  
  107.     skipmenu=FALSE;
  108.     // create the prompt string
  109.  
  110.  
  111.     if (N_ND->NodeFlags & NFLG_OLMSWAITING)
  112.     {
  113.       DOOR_SystemDoor("ReadOLM",NULL);
  114.     }
  115.  
  116.     if ((HBBS_TimeLeft()<0) && (N_ND->User.Acs.Data[ACS_UNLIMTIME]=='N'))
  117.     {
  118.       if (!DOOR_DisplaySpecialScreen("NOTIME"))
  119.       {
  120.         DOOR_WriteText("You've run out of time!  See you tomorrow...\r\n");
  121.       }
  122.       DOOR_Goodbye();
  123.     }
  124.  
  125.     if (N_ND->OnlineStatus==OS_ONLINE)
  126.     {
  127.       strcpy(prompt,ANSI_RESET);
  128.       strcat(prompt,N_ND->CurrentConf->MenuPrompt);
  129.  
  130.       HBBS_ModifyString(prompt);
  131.  
  132.       // now display it..
  133.  
  134.       DOOR_WriteText(prompt);
  135.       DOOR_WriteText(" ");
  136.       DOOR_GetLine(GL_EDIT|GL_DISPLAY|GL_HISTORY,'\0',0,0,NULL);
  137.       strNcpy(command,N_ND->CurrentLine,79);
  138.  
  139.       RemoveSpaces(command);
  140.  
  141.       // *C* strip spaces from end of "command" and from the start
  142.  
  143.       if (N_ND->OnlineStatus==OS_ONLINE && command[0])
  144.       {
  145.         // ok, everything before the first space is the doorname, anything after
  146.         // it are the options.
  147.  
  148.         tmpval=iposition(" ",command);
  149.  
  150.         if (tmpval<0) tmpval=strlen(command);
  151.  
  152.         strNcpy(doorname,command,tmpval);
  153.         strfcpy(options,command,tmpval+1);
  154.  
  155.         if (strcmp(doorname,"?")==0)
  156.         {
  157.           DOOR_DisplaySpecialScreen("MENU");
  158.           skipmenu=TRUE; // so we don't display it twice..)
  159.         }
  160.         else
  161.         {
  162.           if (!DOOR_UserDoor(doorname,options))
  163.           {
  164.             DOOR_WriteText("\n\rUnknown Command! - Type ? For Help!\n\r\n\r");
  165.           }
  166.         }
  167.       }
  168.  
  169.       if ((CarrierLost()) && (N_ND->LoginType==LOGIN_REMOTE)) N_ND->OnlineStatus = OS_OFFLINE;
  170.     }
  171.   } while (N_ND->OnlineStatus == OS_ONLINE); // && stricmp("G",doorname));
  172. }
  173.  
  174. int main(int argc,char *argv[])
  175. {
  176.   if (sscanf(argv[1],"%d",&N_NodeNum)==0)
  177.   {
  178.     printf("Invalid/No Paramaters for door!\n");
  179.     exit (20);
  180.   }
  181.   init("CmdPrompt");
  182.  
  183.   if (BBSGlobal=HBBS_GimmeBBS())
  184.   {
  185.     if (N_ND=HBBS_NodeDataPtr(N_NodeNum)) // this should not fail in normal circumstances..
  186.     {
  187.       DoorMain();
  188.     }
  189.   }
  190.   cleanup(0);
  191. }
  192.